<?php
declare (strict_types = 1);

namespace app\api\controller;

use think\Request;

class Sign
{


    public function sign(Request $request){
        $sign_time = date('Y-m-d',time());
        $uid = $request->uid;
        $data = \app\api\model\Sign::where('uid',$uid)->select()->toArray();
        $dates =[];
       foreach ($data as $v){
           $dates [] = date('Y-m-d',$v['sign_time']);
       }
       if (in_array($sign_time,$dates)){
           return json(['code'=>300,'msg'=>'今天已经签到']);
       }else{
           $arr=[];
           $arr['add_time'] = time();
           $arr['sign_time'] = time();
           $arr['uid'] = $uid;
           $flag = \app\api\model\Sign::create($arr);
           if ($flag){
               return json(['code'=>200,'msg'=>'签到成功']);
           } else{
               return json(['code'=>300,'msg'=>'签到失败']);
           }
       }
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index(Request $request)
    {
        $uid = $request->uid;
        $data = \app\api\model\Sign::where('uid',$uid)->select()->toArray();
        $dates =[];
        foreach ($data as $v){
            $dates [] = date('Y-m-d',$v['sign_time']);
        }
        return  json(['code'=>200,'data'=>$dates]);
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
}
